import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';

/**
 * Generated class for the DemoDetailPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-demo-detail',
  templateUrl: 'demo-detail.html',
})
export class DemoDetailPage {
  index: any;
  page_data: any;
  //promis方式回调
  reCallback: any;
  objectKeys = Object.keys;
  constructor(public navCtrl: NavController, public navParams: NavParams) {
    // this.page_data = this.navParams.get("param")
    this.index = this.navParams.get("index");
    //与源数据分离，保存后回传编辑过的数据，由列表自己更新
    this.page_data = eval("(" + JSON.stringify(this.navParams.get("param")) + ")");
    this.reCallback = this.navParams.get("reCallback");
  }

  object_Type(data: any) {
    return typeof (data);
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad DemoDetailPage');
  }

  save_data() {
    //调用前页的方法回传变更后的参数
    this.reCallback('saveok', this.page_data, this.index).then(() => {
      //回调前页方法后关闭本页
      this.navCtrl.pop();
    })
  }

}
